﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Web;

namespace SuggestionService
{
    public class CacheManager
    {
        public static object GetFromCache(string key)
        {
            ObjectCache cache = MemoryCache.Default;
            object item = null;
            
            if(cache.Contains(key))
            {
                item = cache.GetCacheItem(key).Value;
            }
            return item;
        }

        public static void PutIntoCache(string key, object item, int slidingDuration)
        {
            ObjectCache cache = MemoryCache.Default;
            if(cache.Contains(key))
            {
                cache[key] = item;
            }
            else
            {
                cache.Add(new CacheItem(key, item),
                          new CacheItemPolicy {SlidingExpiration = TimeSpan.FromSeconds(slidingDuration)});
            }

        }
    }
}